//user.js
export default {
  namespaced: true, //命名空间必须写
  state: {
    avatar: uni.getStorageSync("avatar") || "", //头像
    nickName: uni.getStorageSync("nickName") || "", //昵称
    mobile: uni.getStorageSync("mobile") || "", //手机号
    location: uni.getStorageSync("location") || "广州",
    token: uni.getStorageSync("token") || "",
    openid: uni.getStorageSync("openid") || "",
  },
  getters: {
    getState(state) {
      return state;
    },
  },
  //唯一修改state值的方法
  // commit
  mutations: {
    changeAvatar(state, data) {
      state.avatar = data;
      uni.setStorageSync("avatar", state.avatar);
    },
    changeNickName(state, data) {
      state.nickName = data;
      uni.setStorageSync("nickName", state.nickName);
    },
    changeMobile(state, data) {
      state.mobile = data;
      uni.setStorageSync("mobile", state.mobile);
    },
    changeOpenid(state, data) {
      state.openid = data;
      uni.setStorageSync("openid", state.openid);
    },
    // 修改内容
    changeToken(state, data) {
      state.token = data;
      uni.setStorageSync("token", state.token);
    },
    //定位
    changeLocation(state, data) {
      state.location = data;
      uni.setStorageSync("location", state.location);
    },
  },
  // 异步的操作
  // dispatch
  actions: {},
};
